<template>
    <div class="device-list" v-loading="showLoading">
        <div style="margin-top: -20px;padding-bottom: 10px;">
            <ul class="global-operation-list" style="margin-top: 20px;">
                <li class="global-operation-left">
                    <ul class="global-filter-list">
                        <li class="global-filter-item">
                            <el-button type="primary" class="global-filter-item-search"
                                :style="{ background: $store.state.theme.theme_color || '#03C192', border: 'none' }"
                                @click="chooseYiHuoProject()">选择易货项目</el-button>
                        </li>
                        <li class="global-filter-item">
                            <el-button type="primary" class="global-filter-item-search"
                                :style="{ background: $store.state.theme.theme_color || '#03C192', border: 'none' }"
                                @click="chooseMediumOtherProject()">选择其他项目</el-button>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
        <div class="choose_project_list">
            <div class="project_list">
                <div class="project_item" v-if="chooseYihuoProjectShowList && chooseYihuoProjectShowList.length > 0">
                    <div class="project_item_title">
                        易货项目：<el-button type="text" @click="clearProjectPackage(2)">清空</el-button>
                    </div>
                    <div class="project_item_content">
                        <div class="project_item_content_list" v-for="(item, index) in chooseYihuoProjectShowList"
                            :key="index">
                            <div class="project_item_content_item">
                                <el-button-group>
                                    <el-button size="mini" round @click="getOneProjectPackageListMsg(item.id, 2, item.brands)">{{ item.brands }}</el-button>
                                    <el-button size="mini" round type="danger" icon="el-icon-delete" @click="doDelChooseProject(index, 2)"></el-button>
                                </el-button-group>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="project_item"
                    v-if="chooseMediumOtherProjectShowList && chooseMediumOtherProjectShowList.length > 0">
                    <div class="project_item_title">
                        其他项目：<el-button type="text" @click="clearProjectPackage(3)">清空</el-button>
                    </div>
                    <div class="project_item_content">
                        <div class="project_item_content_list" v-for="(item, index) in chooseMediumOtherProjectShowList"
                            :key="index">
                            <div class="project_item_content_item">
                                <el-button-group>
                                    <el-button size="mini" round @click="getOneProjectPackageListMsg(item.id, 3, item.brands)">{{ item.brands }}</el-button>
                                    <el-button size="mini" round type="danger" icon="el-icon-delete" @click="doDelChooseProject(index, 3)"></el-button>
                                </el-button-group>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div>
            <Calendar v-if="dateCalendarDialog" :calendar-show-type="1" :project-choose-map="projectChooseMap"
                :calendar-scroll-left-status="calendarScrollLeftStatus" :data-offline-list="dataPackageOfflineList"
                :calendar-type="calendarType" @scrollEndCalendar="scrollEndCalendar"
                @scrollStartCalendar="scrollStartCalendar" :calendar-start-time="calendarStartTime"
                :calendar-end-time="calendarEndTime" :operationList="operationList"></Calendar>
        </div>

        <el-dialog :title="chooseProjectTitle" :visible.sync="chooseMediumOtherProjectDialogVisible" width="50%"
            :before-close="chooseMediumOtherProjectHandleClose">
            <div>
                <div class="device-list">
                    <ul class="global-operation-list" style="margin-top: 20px;">
                        <li class="global-operation-left">
                            <ul class="global-filter-list">
                                <li class="global-filter-item">
                                    <h2 class="global-filter-item-title">关键字：</h2>
                                    <el-input v-model="searchForm.keyword" @change="reProjectPosts"
                                        placeholder="项目名称、品牌" clearable></el-input>
                                </li>
                                <li class="global-filter-item" v-if="chooseProjectType == 3">
                                    <h2 class="global-filter-item-title">类型：</h2>
                                    <el-select v-model="searchForm.otherProjectType" placeholder="请选择类型" clearable>
                                        <el-option v-for="item in otherProjectTypeList" :key="item.id"
                                            :label="item.sysValueName" :value="item.id">
                                        </el-option>
                                    </el-select>
                                </li>
                                <li class="global-filter-item">
                                    <el-button type="primary" class="global-filter-item-search"
                                        :style="{ background: $store.state.theme.theme_color || '#03C192', border: 'none' }"
                                        @click="reProjectPosts()">搜索</el-button>
                                </li>
                            </ul>
                        </li>
                    </ul>
                    <div class="global-table-content">
                        <div class="global-table">
                            <el-table :data="dataList" :header-cell-style="{
                                background: '#F6F7FA',
                                color: '#333',
                                height: '60px',
                            }" v-loading="tableLoading" :row-style="{ height: '0' }" :cell-style="{ padding: '3px' }"
                                max-height="700" border @selection-change="handleCurrentChangeTable"
                                @select="handleCurrentChangeRow" @select-all="handleCurrentChangeRowAll"
                                ref="multipleProjectTable" v-if="dataList && dataList.length > 0">
                                <el-table-column type="selection" width="55">
                                </el-table-column>
                                <el-table-column prop="projectName" label="项目名称" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column label="品牌名称" prop="brands" show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column label="项目类型" prop="otherProjectTypeName" v-if="chooseProjectType == 3"
                                    show-overflow-tooltip>
                                </el-table-column>
                                <el-table-column label="创建时间" prop="createDate" show-overflow-tooltip>
                                </el-table-column>
                            </el-table>
                            <div class="no-data" v-else
                                style="height: calc(100vh - 130px - 80px);display: flex;align-items: center;justify-content: center;flex-direction: column">
                                <img style="width: 265px;height: 120px;margin-bottom: 32px"
                                    src="@/assets/images/tyNoData.png" alt="" />
                                <div style="font-size: 16px;color: #A5A9B5">暂无数据~</div>
                            </div>
                        </div>
                        <div class="global-page">
                            <div class="global-page-left">
                            </div>
                            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                :page-sizes="pageSizes" :page-size="pageSize" :current-page="pageNum" background
                                layout="sizes, total, prev, pager, next" :total="total">
                            </el-pagination>
                        </div>
                    </div>
                </div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="chooseMediumOtherProjectDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="commitChooseMediumProject">确 定</el-button>
            </span>
        </el-dialog>

        <el-drawer
            :title="projectPackageDrawerTitle"
            :visible.sync="projectPackageDrawer"
            direction="rtl"
            size="50%"
            :before-close="handleCloseProjectPackageDrawer">
            <div class="package_drawer">
                <div class="package_drawer_list">
                    <div class="package_drawer_item" v-for="(item, index) in projectPackageList" :key="index">
                        <el-card class="box-card">
                            <div slot="header" class="clearfix">
                                <span>{{item.mediumName}}</span>
                            </div>
                            <div v-for="(timeItem, timeIndex) in item.mediumTimeList" :key="timeIndex" class="text item">
                                {{ timeItem.chooseDate + ' 至 ' + timeItem.chooseEndDate }}
                            </div>
                        </el-card>
                    </div>
                </div>
            </div>
        </el-drawer>

    </div>
</template>

<script>
import APIProject from "@/api/apiProject";
import APIMediumOtherProject from "@/api/apiMediumOtherProject";
import APISysLabel from "@/api/apiSysLabel";

import Calendar from "@/components/calendar/Calendar";
export default {
    name: "MediumDateShow",
    components: {
        Calendar,
    },
    props: {
        operationList: Array,
    },
    data() {
        return {
            tokenData: {
                token: localStorage.getItem("mujingtoken")
            },
            dateCalendarDialog: false,
            dataPackageOfflineList: [],
            calendarStartTime: new Date().getTime(),
            calendarEndTime: new Date().getTime(),
            calendarType: 1,
            calendarScrollLeftStatus: true,
            destroyCloseDateCalendarDialog: false,
            projectChooseMap: {},
            chooseYihuoProjectList: [],
            chooseMediumOtherProjectList: [],
            chooseYihuoProjectShowList: [],
            chooseMediumOtherProjectShowList: [],
            chooseYihuoProjectIdList: [],
            chooseMediumOtherProjectIdList: [],
            chooseProjectTitle: '选择项目',
            tableLoading: false,
            dataList: [],
            pageSize: 10,
            pageNum: 1,
            total: 0,
            pageSizes: [10, 20, 50, 100],
            chooseMediumOtherProjectDialogVisible: false,
            chooseProjectType: 3, 
            searchForm: {
                keyword: "",
                otherProjectType: null,
            },
            otherProjectTypeList: [],
            projectPackageList: [],
            projectPackageDrawer: false,
            projectPackageDrawerTitle: '',
            showLoading: false,
        };
    },
    activated() {
        this.showLoading = true
        this.showPackage(1);
    },
    created() {},
    methods: {
        clearProjectPackage(type){
            if(type == 2){
                this.chooseYihuoProjectShowList = []
                this.chooseYihuoProjectList = []
                this.chooseYihuoProjectIdList = []
            }else if(type == 3){
                this.chooseMediumOtherProjectShowList = []
                this.chooseMediumOtherProjectList = []
                this.chooseMediumOtherProjectIdList = []
            }
            this.showPackage(1);
        },
        handleCloseProjectPackageDrawer(){
            this.projectPackageDrawer = false
        },
        doDelChooseProject(index, type){
            this.$bus.$emit("show-loading", true);
            if(type == 2){
                this.chooseYihuoProjectShowList.splice(index, 1)
                this.chooseYihuoProjectList.splice(index, 1)
                this.chooseYihuoProjectIdList.splice(index, 1)
            }else if(type == 3){
                this.chooseMediumOtherProjectShowList.splice(index, 1)
                this.chooseMediumOtherProjectList.splice(index, 1)
                this.chooseMediumOtherProjectIdList.splice(index, 1)
            }
            this.showPackage(1);
        },
        getOneProjectPackageListMsg(projectId, type, brands) {
            this.$bus.$emit("show-loading", true);
            this.projectPackageDrawerTitle = brands
            const params = {
                token: this.$store.state.token,
                projectId: projectId,
                lineType: type
            };
            APIProject.getOneProjectPackageList(params).then((res) => {
                if (res.key === 1000) {
                    this.projectPackageDrawer = true
                    res = res.result.list;
                    res.forEach(item => {
                        if (item.createTime) {
                            item.createDate = this.$moment(item.createTime).format("YYYY-MM-DD HH:mm");
                        }
                        if(item.mediumTimeList && item.mediumTimeList.length > 0){
                            item.mediumTimeList.forEach(timeItem => {
                                if(timeItem.chooseTime){
                                    timeItem.chooseDate = this.$moment(timeItem.chooseTime).format("YYYY-MM-DD");
                                }
                                if(timeItem.chooseEndTime){
                                    timeItem.chooseEndDate = this.$moment(timeItem.chooseEndTime).format("YYYY-MM-DD");
                                }
                            })
                        }
                    })
                    this.projectPackageList = res
                }
                this.$bus.$emit("show-loading", false);
            });
        },
        commitChooseMediumProject() {
            this.chooseMediumOtherProjectDialogVisible = false
            this.chooseYihuoProjectShowList = JSON.parse(JSON.stringify(this.chooseYihuoProjectList))
            this.chooseMediumOtherProjectShowList = JSON.parse(JSON.stringify(this.chooseMediumOtherProjectList))
            this.showPackage(1)
        },
        handleCurrentChangeRow(list, item){
            if (this.chooseProjectType == 3) {
                if (this.chooseMediumOtherProjectIdList && this.chooseMediumOtherProjectIdList.length > 0) {
                    if (!this.chooseMediumOtherProjectIdList.includes(item.id)) {
                        this.chooseMediumOtherProjectIdList.push(item.id)
                        this.chooseMediumOtherProjectList.push(item)
                    }else{
                        let index = this.chooseMediumOtherProjectIdList.indexOf(item.id)
                        this.chooseMediumOtherProjectIdList.splice(index, 1)
                        this.chooseMediumOtherProjectList.splice(index, 1)
                    }
                } else {
                    this.chooseMediumOtherProjectIdList.push(item.id)
                    this.chooseMediumOtherProjectList.push(item)
                }
            } else {
                if (this.chooseYihuoProjectIdList && this.chooseYihuoProjectIdList.length > 0){
                    if (!this.chooseYihuoProjectIdList.includes(item.id)) {
                        this.chooseYihuoProjectIdList.push(item.id)
                        this.chooseYihuoProjectList.push(item)
                    }else{
                        let index = this.chooseYihuoProjectIdList.indexOf(item.id)
                        this.chooseYihuoProjectIdList.splice(index, 1)
                        this.chooseYihuoProjectList.splice(index, 1)
                    }
                } else {
                    this.chooseYihuoProjectIdList.push(item.id)
                    this.chooseYihuoProjectList.push(item)
                }
            }
        },
        handleCurrentChangeRowAll(val){
            if(val && val.length > 0){
                val.forEach(item => {
                    if (this.chooseProjectType == 3) {
                        if (this.chooseMediumOtherProjectIdList && this.chooseMediumOtherProjectIdList.length > 0) {
                            if (!this.chooseMediumOtherProjectIdList.includes(item.id)) {
                                this.chooseMediumOtherProjectIdList.push(item.id)
                                this.chooseMediumOtherProjectList.push(item)
                            }
                        } else {
                            this.chooseMediumOtherProjectIdList.push(item.id)
                            this.chooseMediumOtherProjectList.push(item)
                        }
                    } else {
                        if (this.chooseYihuoProjectIdList && this.chooseYihuoProjectIdList.length > 0){
                            if (!this.chooseYihuoProjectIdList.includes(item.id)) {
                                this.chooseYihuoProjectIdList.push(item.id)
                                this.chooseYihuoProjectList.push(item)
                            }
                        } else {
                            this.chooseYihuoProjectIdList.push(item.id)
                            this.chooseYihuoProjectList.push(item)
                        }
                    }
                })
            }else{
                this.dataList.forEach(item => {
                    if (this.chooseProjectType == 3) {
                        if (this.chooseMediumOtherProjectIdList && this.chooseMediumOtherProjectIdList.length > 0) {
                            if (this.chooseMediumOtherProjectIdList.includes(item.id)) {
                                let index = this.chooseMediumOtherProjectIdList.indexOf(item.id)
                                this.chooseMediumOtherProjectIdList.splice(index, 1)
                                this.chooseMediumOtherProjectList.splice(index, 1)
                            }
                        }
                    } else {
                        if (this.chooseYihuoProjectIdList && this.chooseYihuoProjectIdList.length > 0){
                            if (this.chooseYihuoProjectIdList.includes(item.id)) {
                                let index = this.chooseYihuoProjectIdList.indexOf(item.id)
                                this.chooseYihuoProjectIdList.splice(index, 1)
                                this.chooseYihuoProjectList.splice(index, 1)
                            }
                        }
                    }
                })
            }
        },
        handleCurrentChangeTable(val) {
            // console.log("选择的===》", val)
            // if(val && val.length > 0){
            //     val.forEach(item => {
            //         if (this.chooseProjectType == 3) {
            //             if (this.chooseMediumOtherProjectIdList && this.chooseMediumOtherProjectIdList.length > 0) {
            //                 if (!this.chooseMediumOtherProjectIdList.includes(item.id)) {
            //                     this.chooseMediumOtherProjectIdList.push(item.id)
            //                     this.chooseMediumOtherProjectList.push(item)
            //                 }
            //             } else {
            //                 this.chooseMediumOtherProjectIdList.push(item.id)
            //                 this.chooseMediumOtherProjectList.push(item)
            //             }
            //         } else {
            //             if (this.chooseYihuoProjectIdList && this.chooseYihuoProjectIdList.length > 0){
            //                 if (!this.chooseYihuoProjectIdList.includes(item.id)) {
            //                     this.chooseYihuoProjectIdList.push(item.id)
            //                     this.chooseYihuoProjectList.push(item)
            //                 }
            //             } else {
            //                 this.chooseYihuoProjectIdList.push(item.id)
            //                 this.chooseYihuoProjectList.push(item)
            //             }
            //         }
            //     })
            // }else{
            //     this.chooseYihuoProjectList = []
            //     this.chooseMediumOtherProjectList = []
            //     this.chooseYihuoProjectIdList = []
            //     this.chooseMediumOtherProjectIdList = []
            // }
        },
        // 分页pageSize改变
        handleSizeChange(e) {
            this.pageSize = e;
            this.reProjectPosts();
        },
        // 分页pageNum改变
        handleCurrentChange(e) {
            this.pageNum = e;
            if (this.chooseProjectType == 3) {
                this.getMediumOtherProjectPost();
            } else {
                this.getYiHuoProjectPost()
            }
        },
        // 重新请求
        reProjectPosts() {
            this.pageNum = 1;
            this.dataList = [];
            if (this.chooseProjectType == 3) {
                this.getMediumOtherProjectPost();
            } else {
                this.getYiHuoProjectPost()
            }
        },
        getYiHuoProjectPost() {
            this.$bus.$emit("show-loading", true);
            const params = {
                token: this.$store.state.token,
                pageNum: this.pageNum,
                pageSize: this.pageSize
            };
            if (this.searchForm.keyword) {
                params.keyword = this.searchForm.keyword;
            }
            APIProject.getProjectManageList(params).then((res) => {
                if (res.key === 1000) {
                    this.total = res.result.count;
                    res = res.result.list;
                    res.forEach(item => {
                        if (item.createTime) {
                            item.createDate = this.$moment(item.createTime).format("YYYY-MM-DD HH:mm");
                        }
                    })
                    this.dataList = res;
                    this.$nextTick(() => {
                        if (this.chooseYihuoProjectIdList && this.chooseYihuoProjectIdList.length > 0) {
                            this.dataList.forEach(dataItem => {
                                this.chooseYihuoProjectIdList.forEach(item => {
                                    if (item == dataItem.id) {
                                        this.$refs.multipleProjectTable.toggleRowSelection(dataItem);
                                    }
                                })
                            })
                        }
                    })
                }
                this.$bus.$emit("show-loading", false);
            });
        },
        getMediumOtherProjectPost() {
            this.$bus.$emit("show-loading", true);
            const params = {
                token: this.$store.state.token,
                pageNum: this.pageNum,
                pageSize: this.pageSize
            };
            if (this.searchForm.keyword) {
                params.keyword = this.searchForm.keyword;
            }
            if (this.searchForm.otherProjectType) {
                params.otherProjectType = this.searchForm.otherProjectType;
            }
            APIMediumOtherProject.getMediumOtherProjectList(params).then((res) => {
                if (res.key === 1000) {
                    this.total = res.result.count;
                    res = res.result.list;
                    res.forEach(item => {
                        if (item.createTime) {
                            item.createDate = this.$moment(item.createTime).format("YYYY-MM-DD HH:mm");
                        }
                    })
                    this.dataList = res;
                    this.$nextTick(() => {
                        if (this.chooseMediumOtherProjectIdList && this.chooseMediumOtherProjectIdList.length > 0) {
                            this.dataList.forEach(dataItem => {
                                this.chooseMediumOtherProjectIdList.forEach(item => {
                                    if (item == dataItem.id) {
                                        this.$refs.multipleProjectTable.toggleRowSelection(dataItem);
                                    }
                                })
                            })
                        }
                    })
                }
                this.$bus.$emit("show-loading", false);
            });
        },
        chooseYiHuoProject() {
            this.chooseProjectType = 2
            this.chooseProjectTitle = '选择易货项目'
            this.searchForm = {
                keyword: "",
                otherProjectType: null,
            }
            this.pageNum = 1;
            this.dataList = [];
            this.getYiHuoProjectPost();
            this.chooseMediumOtherProjectDialogVisible = true;
        },
        // 选择其他项目弹窗
        chooseMediumOtherProject() {
            this.chooseProjectType = 3
            this.chooseProjectTitle = '选择其他项目'
            this.searchForm = {
                keyword: "",
                otherProjectType: null,
            }
            this.pageNum = 1;
            this.dataList = [];
            this.getMediumOtherProjectPost();
            this.chooseMediumOtherProjectDialogVisible = true;
        },
        chooseMediumOtherProjectHandleClose() {
            this.chooseMediumOtherProjectDialogVisible = false;
        },
        closeDateCalendarDialog(){
            this.calendarStartTime = new Date().getTime()
            this.calendarEndTime = this.calendarStartTime
            this.dataPackageOfflineList = []
            this.calendarScrollLeftStatus = true
            this.calendarType = 1;
        },
        scrollStartCalendar(val){
            // 日历滑到最左边了
            this.getLastMonthStart(new Date(val.dateTime))
            this.getLastMonthEnd(new Date(val.dateTime))
            this.$nextTick(() => {
                this.showPackage(2)
            })
        },
        getLastMonthStart(currentDate){
            // 获取上个月的第一天
            // 将月份减1
            currentDate.setMonth(currentDate.getMonth() - 1);
            // 将日期设置为1
            currentDate.setDate(1);
            // 获取上个月的第一天
            let firstDayOfLastMonth = new Date(currentDate.getTime());
            console.log("-->", currentDate.getTime())
            this.calendarStartTime = firstDayOfLastMonth.getTime();
        },
        getLastMonthEnd(currentDate){
            // 获取上个月的最后一天
            // 将月份减1
            currentDate.setMonth(currentDate.getMonth());
            currentDate.setDate(0);
            currentDate.setHours(23, 59, 59, 999);
            let firstDayOfLastMonth = new Date(currentDate.getTime());
            this.calendarEndTime = firstDayOfLastMonth.getTime();
        },
        scrollEndCalendar(val){
            // 日历滑到最右边了
            this.getNextMonthStart(new Date(val.dateTime))
            this.getNextMonthEnd(new Date(val.dateTime))
            this.$nextTick(() => {
                this.showPackage(2)
            })
        },
        getNextMonthStart(currentDate){
            // 获取下个月的第一天
            // 将月份加1
            currentDate.setMonth(currentDate.getMonth() + 2);
            // 将日期设置为1
            currentDate.setDate(0);
            currentDate.setHours(0,0,0,0);
            // 获取下个月的第一天
            let firstDayOfNextMonth = new Date(currentDate.getTime());
            firstDayOfNextMonth.setDate(1);
            this.calendarStartTime = firstDayOfNextMonth.getTime();
        },
        getNextMonthEnd(currentDate){
            // 获取下个月的最后一天
            let lastDayOfNextMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 2, 0, 23, 59, 59, 999)
            this.calendarEndTime = lastDayOfNextMonth.getTime();
        },
        showPackage(type){
            this.calendarScrollLeftStatus = false;
            this.$bus.$emit("show-loading", true);
            this.showLoading = true
            if(type == 1){
                this.getLastMonthStart(new Date())
                this.getNextMonthEnd(new Date())
                this.dataPackageOfflineList = []
                this.projectChooseMap = {}
                this.calendarType = this.calendarType + 1;
            }
            console.log(type, JSON.parse(JSON.stringify(this.calendarStartTime)))
            let that = this;
            let params = {
                startTime: this.calendarStartTime,
                endTime: this.calendarEndTime,
            }
            if (this.chooseYihuoProjectIdList && this.chooseYihuoProjectIdList.length > 0){
                params.showChooseProjectType = 1
                params.chooseYihuoProjectIds = this.chooseYihuoProjectIdList.join(",")
            }
            if (this.chooseMediumOtherProjectIdList && this.chooseMediumOtherProjectIdList.length > 0) {
                params.showChooseProjectType = 1
                params.chooseMediumOtherProjectIds = this.chooseMediumOtherProjectIdList.join(",")
            }
            APIProject.viewOfflineHasPackageProjectList(params).then((res) => {
                if (res.key === 1000) {
                    let result = res.result
                    let list = result.list
                    let qList = []
                    let projectChooseMap = this.projectChooseMap
                    list.forEach(item => {
                        if(item.projectMsgDTOList && item.projectMsgDTOList.length > 0){
                            item.projectMsgDTOList.forEach(projectItem => {
                                if(projectItem && projectItem.chooseTime){
                                    projectItem.date = this.$moment(projectItem.chooseTime).format("yyyy-MM-DD")
                                    if(projectChooseMap[item.id + '-' + this.$moment(projectItem.chooseTime).format("YYYY-MM-DD")]){
                                        let hasJoin = false;
                                        projectChooseMap[item.id + '-' + this.$moment(projectItem.chooseTime).format("YYYY-MM-DD")].forEach(aItem => {
                                            if(aItem.id == projectItem.id){
                                                hasJoin = true
                                            }
                                        })
                                        if(!hasJoin){
                                            projectChooseMap[item.id + '-' + this.$moment(projectItem.chooseTime).format("YYYY-MM-DD")].push(projectItem)
                                        }
                                    }else{
                                        projectChooseMap[item.id + '-' + this.$moment(projectItem.chooseTime).format("YYYY-MM-DD")] = [projectItem]
                                    }
                                }
                            })
                        }
                    })
                    this.projectChooseMap = projectChooseMap
                    list.forEach(item => {
                        for(var i = 0; i < item.num; i++){
                            item.rank = i;
                            qList.push(JSON.parse(JSON.stringify(item)))
                        }
                    })
                    qList.forEach(item => {
                        item.projectMsgDTOList = item.projectList
                    })
                    let offlineList = []
                    qList.forEach(item => {
                        let projectMap = {}
                        let dto = item
                        dto.chooseNum = item.num
                        if(dto.projectMsgDTOList && dto.projectMsgDTOList.length > 0){
                            dto.projectChooseList = dto.projectMsgDTOList
                            dto.projectMsgDTOList.forEach(projectItem => {
                                if(projectItem && projectItem.chooseTime){
                                    projectItem.date = this.$moment(projectItem.chooseTime).format("YYYY-MM-DD");
                                    let a = projectMap[projectItem.date];
                                    if(a){
                                        a.push(projectItem.projectName);
                                    }else{
                                        projectMap[projectItem.date] = [projectItem.projectName];
                                    }
                                }
                            })
                        }
                        dto.projectMap = projectMap;
                        offlineList.push(dto)
                    })
                    let dtoList = []
                    dtoList = offlineList
                    let showOfflineList = [
                        {
                            name: ''
                        },
                    ]
                    let showList = showOfflineList.concat(dtoList)
                    that.dataPackageOfflineList = JSON.parse(JSON.stringify(showList))
                    this.calendarType = this.calendarType + 1;
                    if(type == 1){
                        that.dateCalendarDialog = true
                    }
                    this.$bus.$emit("show-loading", false);
                    this.showLoading = false
                }
            });
        },
    },
};
</script>

<style>
.device-list{
    padding: 20px 0;
}
.el-button-group{
    display: inline-flex;
}
.choose_project_list{
    padding-left: 20px;
    margin-bottom: 20px;
    margin-top: -20px;
}
.project_item{
    /* display: inline-block; */
    margin: 5px 0;
}
.project_item_content{
    padding-top: 5px;
    display: flex;
    flex-wrap: wrap;
    width: 100%;
}
.project_item_content_list{
    padding-left: 10px;
    display: flex;
    padding-bottom: 5px;
}
.project_item_content_item{
}
.package_drawer{
    margin: 5px 20px;
}
.package_drawer_item{
    padding-bottom: 10px;
}
</style>

<style lang="sass">
</style>
